<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org"
	xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<meta charset="utf-8">
<head th:include="include :: header"></head>

<link href="../static/azxcrm/css/audit.css"
	th:href="@{/azxcrm/css/audit.css}" rel="stylesheet" />
	
<!-- 引用控制层插件样式 -->
<link href="../static/ajax/libs/zyupload/control/css/zyUpload.css" th:href="@{/ajax/libs/zyupload/control/css/zyUpload.css}" rel="stylesheet"/>
<body>
	<div class="g-audit">
		<!-- 头部结构 -->
		<div class="add_order clearfix">
			<div class="addorder_left clearfix">订单详情</div>
		</div>
		<!-- 头部结构 -->

		<div class="g-orderDetail">
			<!-- 订单类型 -->
			<div class="s-information">
				<div class="tab-pane fade in active s-infor-detail">
					<ul class="clearfix">
						<li><span>订单号：</span><span th:text="${order.orderNum}">未知</span></li>
						<li>
							<span>*审核类型：</span>
							<span th:if="${order.auditType} == 0">未知</span>
							<span th:if="${order.auditType} == 1">成单审核</span>
							<span th:if="${order.auditType} == 2">退单审核</span>
						</li>
						<li><span>订单类型：</span><span th:text="${order.typeName}"></span></li>
						<li><span>订单创建时间：</span><span th:text="${order.createTime}"></span></li>
					</ul>
				</div>
			</div>
			<!-- 订单类型 -->

			<!-- 客户信息 -->
			<div class="s-information2" th:if="${order.clueId}!=0">
				<div class="s-infor clearfix">
					<h4 class="pos-rel">客户信息</h4>
					<span class="s-customer" data-toggle="modal" data-target="#myModa2">修改客户信息</span>
				</div>

				<div class="tab-pane fade in active s-infor-detail">
					<ul class="clearfix">
						<li><span>姓名：</span><span th:text="${order.customerClue.customerName}"></span></li>
						<li><span>手机号码：</span><span th:text="${order.customerClue.customerCellphone}"></span></li>
						<li><span>身份证号码：</span><span th:text="${order.customerClue.customerIdentityNum}"></span></li>
					</ul>
				</div>
			</div>
			<div class="s-information2" th:if="${order.clueId}==0">
				<div class="s-infor clearfix">
					<h4 class="pos-rel">客户信息</h4>
				</div>
				<div class="tab-pane fade in active s-infor-detail">
					<ul class="clearfix">
						<li><span>姓名：</span><span th:text="${orderDeal.customerInfo.name}"></span></li>
						<li><span>手机号码：</span><span th:text="${orderDeal.customerInfo.cellphone}"></span></li>
						<li><span>身份证号码：</span><span th:text="${orderDeal.customerInfo.identityNum}"></span></li>
					</ul>
				</div>
			</div>
			<!-- 客户信息 -->

			<!-- 业务员信息 -->
			<div class="s-information3">
				<div class="s-infor clearfix">
					<h4 class="pos-rel">业务员信息</h4>
				</div>

				<div class="tab-pane fade in active s-infor-detail">
					<ul class="clearfix">
						<li><span>姓名：</span><span th:text="${order.user.userName}"></span></li>
						<li><span>手机号码：</span><span th:text="${order.user.phonenumber}"></span></li>
						<li><span>部门：</span><span th:text="${order.deptName}"></span></li>
					</ul>
				</div>
			</div>
			<!-- 业务员信息 -->

			<!-- 业务员信息 -->
			<div class="s-information4">
				<div class="s-infor clearfix">
					<h4 class="pos-rel">产品信息</h4>
				</div>

				<div class="tab-pane fade in active s-infor-detail">
					<ul class="clearfix">
						<li><span>产品：</span><span th:text="${order.productInfo.fullName}"></span></li>
						<li><span>金额：</span><span th:text="${order.productInfo.productPrice}"></span></li>
						<li><span>使用期限：</span><span th:text="${order.productInfo.productTerm}"></span>个月</li>
					</ul>
				</div>
			</div>
			<!-- 业务员信息 -->

			<div class="g-contact">
				<h4 class="pos-rel">合同信息</h4>
				<div class="g-con-num">
					<form role="form">
						<div class="form-group clearfix">
							<label for="name" class="add_label">*合同号：</label> 
							<!-- 成单审核 -->
							<input type="text" class="form-control text_input" th:if="${order.auditType} == 1" name="contractId">
							<!-- 退单审核 -->
							<input type="text" class="form-control text_input" th:if="${order.auditType} == 2" th:value="${order.orderDeal.contractId}" readonly="readonly" name="contractId">
						</div>
					</form>
				</div>
				<!-- 合同信息 -->
				<div class="g-img-box full">
	                <div class=" img-section">
	                    <p class="up-p">合同源文件：</p>
	                    
	                    <!-- 成单审核 -->
	                    <div th:id="${order.auditType} == 1? 'init' :''" th:class="${order.auditType} == 1? 'init' :''" ></div> 
	                    <!-- 退单审核 -->
	                    <div class="z_photo upimg-div clear" th:style="${order.auditType} != 2 ? 'display:none':'display:block'">			 
                            <section class="z_file fl">
                           	 	<img  th:each="dealImagesList:${dealImagesList}" th:src="@{${dealImagesList}}" class="add-img">
                            </section>
                        </div>
	                   </div> 
	                </div>


				<div class="g-img-box full" th:style="${order.auditType} == 2 ? 'display:block':'display:none'">
					<div class=" img-section">
						 <p class="up-p">退单理由：</p>
						<span th:text="${order.refundReason}?'':${order.refundReason}"></span>
						 <p class="up-p">退单凭证：</p>
						 <div th:id="init" th:class="init" ></div> 
					</div>
				</div>
			</div>
                 
				<div class="opinion" style="padding-bottom: 40px;">
					<span>审核意见：</span>
					<div class="btn-group">
						<input name="taskId" type="hidden" th:value="${taskId}">
						<input name="clueId" type="hidden" th:value="${order.clueId}">
						<input name="shortToken" type="hidden" th:value="${token}" id="shortToken">
						<input name="auditType" type="hidden" th:value="${order.auditType}">
						<input name="orderId" type="hidden" th:value="${order.orderId}">
						<button type="button" class="btn btn-warning dropdown-toggle" id="auditPass" onclick="auditOrder('pass')" >通过审核</button>
						<button type="button" class="btn btn-default dropdown-toggle" id="auditReject" onclick="auditOrder('reject')" >审核不通过</button>
					</div>
				</div>

			</div>
		</div>

	<!--客户资料修改-->
	<div class="modal fade" id="myModa2">
		<div class="modal-dialog modal-lg">
			<div class="modal-content">
				<!-- 模态框头部 -->
				<div class="modal-header">
					<h4 class="modal-title">
						客户信息 <span class="glyphicon glyphicon-remove-circle"
							data-dismiss="modal"></span>
					</h4>
				</div>
				<!-- 模态框主体 -->
				<div class="modal-body">
					<form>
						<ul class="clearfix">
							<li class="form-group"><label>姓名：</label>
								<input type="hidden" name="clueId" th:value="${order.clueId}"></input>
								<input type="text"  name="customerName" class="form-control"  th:value="${order.customerClue.customerName}">
							</li>
							<li class="form-group"><label>客户背景：</label>
								<input name="customerBackgrounds" th:value="${order.customerClue.customerBackground}" type="hidden">
								<select class="s-rank profession" name="customerBackground" >
									<option th:value="${order.customerClue.customerBackground}" th:text="${order.customerClue.customerBackground}" selected="selected" disabled="disabled"></option>
									<option th:each="customerBackground : ${customerBackgroundList}" th:value="${customerBackground.dictLabel}" th:text="${customerBackground.dictLabel}"></option>
								</select>
							</li>
							<li class="form-group"><label>手机号码：</label>
								<input type="text"  name="customerCellphone" class="form-control"  th:value="${order.customerClue.customerCellphone}" maxlength="11"
								onblur="Tel(this,this.value)">
							</li>
							<li class="form-group"><label>性别：</label> 
								<span class="radio-inline"> <input type="radio" th:field="*{order.customerClue.customerSex}" name="customerSex" value="1">男</span> 
								<span class="radio-inline"><input type="radio"  th:field="*{order.customerClue.customerSex}" name="customerSex" value="2">女</span>
							</li>
							<li class="form-group"><label>年龄：</label>
								<input type="number" class="form-control" name="customerAge" th:value="${order.customerClue.customerAge}" maxlength="3">
							</li>
							<li class="form-group" id="date"><label>出生日期：</label>
                              <select name="year" id="year" class="profession">
                             	 <option th:value="${order.customerClue.customerBirth}?'':${#strings.substring(order.customerClue.customerBirth,0,4)}" th:text="${order.customerClue.customerBirth}?'':${#strings.substring(order.customerClue.customerBirth,0,4)}" selected="selected" disabled="disabled"></option>
                           	  </select>
                              <select name="month" id="month">
                                 <option th:value="${order.customerClue.customerBirth}?'':${#strings.substring(order.customerClue.customerBirth,5,7)}" th:text="${order.customerClue.customerBirth}?'':${#strings.substring(order.customerClue.customerBirth,5,7)}" selected="selected" disabled="disabled"></option>
                              </select>
                              <select id="days" class="day" name="days">
                                  <option th:value="${order.customerClue.customerBirth}?'':${#strings.substring(order.customerClue.customerBirth,8,10)}" th:text="${order.customerClue.customerBirth}?'':${#strings.substring(order.customerClue.customerBirth,8,10)}" selected="selected" disabled="disabled"></option>
                              </select>
                             </li>
                             
                             
							
							<li class="form-group"><label>职位：</label>
								<input name="customerJobs" th:value="${order.customerClue.customerJob}" type="hidden"> 
								<select class="s-rank profession" name="customerJob" >
									<option th:value="${order.customerClue.customerJob}" th:text="${order.customerClue.customerJob}" selected="selected" disabled="disabled"></option>
									<option th:each="job : ${jobList}" th:value="${job.dictLabel}" th:text="${job.dictLabel}"></option>
								</select>
							</li>
							<li class="form-group"><label>身份证号：</label>
								<input type="text" name="customerIdentityNum" class="form-control" th:value="${order.customerClue.customerIdentityNum}" onblur="isCardNo(this,this.value)">
							</li>
							<li class="form-group"><label>电话号码：</label>
								<input type="text" name="customerPhone" class="form-control" th:value="${order.customerClue.customerPhone}" onblur="isTel(this,this.value)">
							</li>
							<li class="form-group"><label>微信：</label>
								<input type="text" name="customerWechatAccount" class="form-control" th:value="${order.customerClue.customerWechatAccount}">
							</li>
							<li class="form-group"><label>紧急联系人：</label>
								<input type="text" name="customerEmergencyContact" class="form-control" th:value="${order.customerClue.customerEmergencyContact}">
							</li>
							<li class="form-group"><label>联系人号码：</label>
								<input type="text" name="customerEmergencyCellphone" class="form-control" th:value="${order.customerClue.customerEmergencyCellphone}" maxlength="11"
								onblur="Tel(this,this.value)">
							</li>
							<li class="form-group"id="g-position" ><label>客户地址：</label>                                    
								<select name="input_province" id="input_province" class="profession" >
									<option th:value="${order.customerClue.customerProvince}" th:text="${order.customerClue.customerProvince}" selected="selected" disabled="disabled"></option>
								</select>                                              
								<select name="input_city" id="input_city" >
									<option th:value="${order.customerClue.customerCity}" th:text="${order.customerClue.customerCity}" selected="selected" disabled="disabled"></option>
								</select>                                              
								<select name="input_area" id="input_area">
									<option th:value="${order.customerClue.customerArea}" th:text="${order.customerClue.customerArea}" selected="selected" disabled="disabled"></option>
								</select>                         
					 		    <input type="text" name="customerAddressDetail" class="form-control" th:value="${order.customerClue.customerAddressDetail}">
							</li>   	  		
						</ul>
						
						<div class="btn-group">
							<button type="button" class="btn btn-warning dropdown-toggle" id="form-customerClue-edit">确认添加</button>
							<button type="button" class="btn btn-default dropdown-toggle" data-dismiss="modal">取消</button>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
	
	<div th:include="include::footer"></div>
	<script src="../static/ajax/libs/zyupload/jquery-1.7.2.js" th:src="@{/ajax/libs/zyupload/jquery-1.7.2.js}"></script>
	<script src="../static/azxcrm/js/address.js" th:src="@{/azxcrm/js/address.js}"></script>
	<script src="../static/azxcrm/js/select.js" th:src="@{/azxcrm/js/select.js}"></script>
	<!-- 引用核心层插件 -->
	<script src="../static/ajax/libs/zyupload/core/zyFile.js" th:src="@{/ajax/libs/zyupload/core/zyFile.js}"></script>
	<!-- 引用控制层插件 -->
	<script src="../static/ajax/libs/zyupload/control/js/zyUpload.js" th:src="@{/ajax/libs/zyupload/control/js/zyUpload.js}"></script>
	<!-- 引用初始化JS -->
	<script src="../static/ajax/libs/zyupload/zyuploadinit.js" th:src="@{/ajax/libs/zyupload/zyuploadinit.js}"></script>
    <script>  	  	
  	  $(function () {
          $("#date").selectDate();		
			$("#days").focusout(function(){
				var year = $("#year option:selected").html()
				var month = $("#month option:selected").html()
				var day = $("#days option:selected").html()
			})
			var html = "";
          $("#input_city").append(html);
          $("#input_area").append(html);
          $.each(pdata,function(idx,item){
              if (parseInt(item.level) == 0) {
                  html += "<option value="+item.code+" >"+ item.names +"</option> ";
              }
          });
          $("#input_province").append(html);
          $("#input_province").change(function(){
              if ($(this).val() == "") return;
              $("#input_city option").remove();
              $("#input_area option").remove();
              //var code = $(this).find("option:selected").attr("exid");
              var code = $(this).find("option:selected").val();
              code = code.substring(0,2);
              var html = "<option value=''>--请选择--</option>";
              $("#input_area option").append(html);
              $.each(pdata,function(idx,item){
                  if (parseInt(item.level) == 1 && code == item.code.substring(0,2)) {
                      html +="<option value="+item.code+" >"+ item.names +"</option> ";
                  }
              });
              $("#input_city ").append(html);
          });

          $("#input_city").change(function(){
              if ($(this).val() == "") return;
              $("#input_area option").remove();
              var code = $(this).find("option:selected").val();
              code = code.substring(0,4);
              var html = "<option value=''>--请选择--</option>";
              $.each(pdata,function(idx,item){
                  if (parseInt(item.level) == 2 && code == item.code.substring(0,4)) {
                      html +="<option value="+item.code+" >"+ item.names +"</option> ";
                  }
              });
              $("#input_area ").append(html);
          });
      })
      
      //客户信息修改
     $("#form-customerClue-edit").click(function(){
   	      edit();
     })
		//身份证验证
		function isCardNo(obj,card) { 
		    var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; 
		    if(reg.test(card) === false)  {        
		    	layer.msg('请输入正确的身份证号码')
		    } 
		}

		//固定电话
		function isTel(obj,card){
		    var reg = /^(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}$/; 
		     if(reg.test(card) === false)  {        
		    	 layer.msg('请输入正确的电话号码')
		     } 
		}
	    function Tel(obj,val){
	        var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
	        if(!myreg.test(val)){
	          layer.msg('请输入正确的手机号码')
	        }else{
	          return true;
	        }
	      }
	function edit() {
		var clueId = $("input[name='clueId']").val();
		var customerName = $("input[name='customerName']").val();						//客户姓名
		var customerBackground = $("select[name='customerBackground']").val();			//客户背景
		if(customerBackground == null){
			customerBackground = $("select[name='customerBackgrounds']").val();
		}
		var customerCellphone = $("input[name='customerCellphone']").val();				//手机号码
		var customerSex = $("input[name='customerSex']").val();							//性别
		var customerAge = $("input[name='customerAge']").val();							//年龄
		
		var year = $("select[name='year']").find("option:selected").text();
		var month = $("select[name='month']").find("option:selected").text();
		var days = $("select[name='days']").find("option:selected").text();	
		var customerBirth = year.substr(0,4)+"-"+month.substr(0,2)+"-"+days.substr(0,2);	//出生日期
		
		var customerJob = $("select[name='customerJob']").val();						//客户职业
		if(customerJob == null){
			customerJob = $("select[name='customerJobs']").val();
		}
		var customerIdentityNum = $("input[name='customerIdentityNum']").val();			//身份证号码
		var customerPhone = $("input[name='customerPhone']").val();						//电话号码
		var customerWechatAccount = $("input[name='customerWechatAccount']").val();		//微信号
		var customerEmergencyContact = $("input[name='customerEmergencyContact']").val();//紧急联系人
		var customerEmergencyCellphone = $("input[name='customerEmergencyCellphone']").val();//紧急联系人手机号码
		
		var customerProvince = $("select[name='input_province']").find("option:selected").text();				//省
		var customerCity = $("select[name='input_city']").find("option:selected").text();						//市
		var customerArea = $("select[name='input_area']").find("option:selected").text();						//区
		var customerAddressDetail = $("input[name='customerAddressDetail']").val();		//详细地址
		
		var myreg=/^[1][3,4,5,7,8][0-9]{9}$/; //手机号码
		var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; //身份证号码 
		if(!myreg.test(customerCellphone)){
			layer.msg('请输入正确的手机号码')
			return false
		}else if(!reg.test(customerIdentityNum)){
			layer.msg('请输入正确的身份证号码')
			return false
		}else if(!myreg.test(customerEmergencyCellphone)){
			layer.msg('请输入正确的紧急联系人手机号码')
			return false
		}else{
			$.ajax({
    			cache : true,
    			type : "POST",
    			url : ctx + "module/customerClue/save",
    			data : {
    				"clueId": clueId,
    				"customerName": customerName,
    				"customerBackground": customerBackground,
    				"customerCellphone": customerCellphone,
    				"customerSex": customerSex,
    				"customerAge": customerAge,
    				"customerBirth": customerBirth,
    				"customerJob": customerJob,
    				"customerIdentityNum": customerIdentityNum,
    				"customerPhone": customerPhone,
    				"customerWechatAccount": customerWechatAccount,
    				"customerEmergencyContact": customerEmergencyContact,
    				"customerEmergencyCellphone": customerEmergencyCellphone,
    				"customerProvince": customerProvince,
    				"customerCity": customerCity,
    				"customerArea": customerArea,
    				"customerAddressDetail": customerAddressDetail,
    			},
    			async : false,
    			error : function(request) {
    				$.modalAlert("系统错误", "error");
    			},
    			success : function(data) {
    				if (data.code == 0) {
    					parent.layer.msg("修改成功成功,正在刷新数据请稍后……",{icon:1,time: 500,shade: [0.1,'#fff']},function(){
    					});
    					$("#myModa2,.modal-backdrop").hide();
    				} else {
    					$.modalAlert(data.msg, "error");
    				}
    	
    			}
    		});
		}
        /* if(customerCellphone==''){
        	$.modalAlert("手机号码不能为空", "error");
        	return false;
        } else if(customerName==''){
        	$.modalAlert("姓名不能为空", "error");
        	return false;
        } else if(customerIdentityNum==''){
        	$.modalAlert("身份证号码不能为空", "error");
        	return false;
        } else{
    		$.ajax({
    			cache : true,
    			type : "POST",
    			url : ctx + "module/customerClue/save",
    			data : {
    				"clueId": clueId,
    				"customerName": customerName,
    				"customerBackground": customerBackground,
    				"customerCellphone": customerCellphone,
    				"customerSex": customerSex,
    				"customerAge": customerAge,
    				"customerBirth": customerBirth,
    				"customerJob": customerJob,
    				"customerIdentityNum": customerIdentityNum,
    				"customerPhone": customerPhone,
    				"customerWechatAccount": customerWechatAccount,
    				"customerEmergencyContact": customerEmergencyContact,
    				"customerEmergencyCellphone": customerEmergencyCellphone,
    				"customerProvince": customerProvince,
    				"customerCity": customerCity,
    				"customerArea": customerArea,
    				"customerAddressDetail": customerAddressDetail,
    			},
    			async : false,
    			error : function(request) {
    				$.modalAlert("系统错误", "error");
    			},
    			success : function(data) {
    				if (data.code == 0) {
    					parent.layer.msg("修改成功成功,正在刷新数据请稍后……",{icon:1,time: 500,shade: [0.1,'#fff']},function(){
    					});
    					$("#myModa2,.modal-backdrop").hide();
    				} else {
    					$.modalAlert(data.msg, "error");
    				}
    	
    			}
    		});
        } */
	}
  	  
  	//提交审核意见
  	function auditOrder(audit){
  		var contractId =  $("input[name='contractId']").val();
  		var auditType =  $("input[name='auditType']").val();
  		var orderId =  $("input[name='orderId']").val();
  		var shortToken =  $("input[name='shortToken']").val();
  		var taskId =  $("input[name='taskId']").val();
  		
  		//校验客户信息
  		var customerName = $("input[name='customerName']").val();						//客户姓名
  		var customerCellphone = $("input[name='customerCellphone']").val();				//手机号码
  		var customerIdentityNum = $("input[name='customerIdentityNum']").val();			//身份证号码
  		var clueId = $("input[name='clueId']").val();
  		if(clueId==0){
  			$.ajax({
    			cache : false,
    			type : "POST",
    			url : ctx + "module/order/auditOrder",
    			data : {
    				"contractId":contractId,
    				"auditType":auditType,
    				"orderId":orderId,
    				"shortToken":shortToken,
    				"taskId":taskId,
    				"audit":audit,
    			},
    			async : false,
    			error : function(request) {
    				$.modalAlert("系统错误", "error");
    			},
    			success : function(data) {
    				if (data.msg == 1) {
    					parent.layer.msg("审核成功成功,正在刷新数据请稍后……",{icon:1,time: 2000,shade: [0.1,'#fff']},function(){
    					});
    					$.parentReload();
    					//$("#myModa2,.modal-backdrop").hide();
    				} else if(data.msg == -2) {
    					//图片缓存已过期
    					$.modalAlert("图片缓存已过期,请重试", "error");
    				} else if(data.msg == -3) {
    					//缓存数据异常
    					$.modalAlert("缓存数据异常,请重试", "error");
    				} else if(data.msg == -4) {
    					$.modalAlert("订单信息异常", "error");
    				} else if(data.msg == -5) {
    					//操作异常
    					$.modalAlert("数据异常请重试", "error");
    				} else {
    					$.modalAlert("数据异常请重试", "error");
    				}
    			}
    			});
  		}else{
  			if(customerCellphone==''){
	        	$.modalAlert("手机号码不能为空", "error");
	        	return false;
	        } else if(customerName==''){
	        	$.modalAlert("姓名不能为空", "error");
	        	return false;
	        } else if(customerIdentityNum==''){
	        	$.modalAlert("身份证号码不能为空", "error");
	        	return false;
	        }else{
	        	$.ajax({
	    			cache : false,
	    			type : "POST",
	    			url : ctx + "module/order/auditOrder",
	    			data : {
	    				"contractId":contractId,
	    				"auditType":auditType,
	    				"orderId":orderId,
	    				"shortToken":shortToken,
	    				"taskId":taskId,
	    				"audit":audit,
	    			},
	    			async : false,
	    			error : function(request) {
	    				$.modalAlert("系统错误", "error");
	    			},
	    			success : function(data) {
	    				if (data.msg == 1) {
	    					parent.layer.msg("审核成功成功,正在刷新数据请稍后……",{icon:1,time: 2000,shade: [0.1,'#fff']},function(){
	    					});
	    					$.parentReload();
	    					//$("#myModa2,.modal-backdrop").hide();
	    				} else if(data.msg == -2) {
	    					//图片缓存已过期
	    					$.modalAlert("图片缓存已过期,请重试", "error");
	    				} else if(data.msg == -3) {
	    					//缓存数据异常
	    					$.modalAlert("缓存数据异常,请重试", "error");
	    				} else if(data.msg == -4) {
	    					$.modalAlert("订单信息异常", "error");
	    				} else if(data.msg == -5) {
	    					//操作异常
	    					$.modalAlert("数据异常请重试", "error");
	    				} else {
	    					$.modalAlert("数据异常请重试", "error");
	    				}
	    			}
	    			});
	        	}
	  		}
  		}
   </script>
</body>
</html>
